package com.letme.web.controller.wxConfig;

import com.letme.common.annotation.Log;
import com.letme.common.core.controller.BaseController;
import com.letme.common.core.domain.AjaxResult;
import com.letme.common.core.page.TableDataInfo;
import com.letme.common.enums.BusinessType;
import com.letme.common.utils.poi.ExcelUtil;
import com.letme.store.domain.WxConfig;
import com.letme.store.service.IWxConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信登录、支付信息配置 Controller
 * @Description
 * @Author lock-xq
 * @Date 2025/9/11 15:19
 **/
@RestController
@Tag(name = "微信配置信息")
@RequestMapping("/wx/config")
public class WxConfigController extends BaseController {

    @Resource
    private IWxConfigService wxConfigService;

    /**
     * 查询微信登录，支付信息列表
     */
    @Operation(summary = "查询微信登录，支付信息列表")
    @PreAuthorize("@ss.hasPermi('wx:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxConfig wxConfig)
    {
        startPage();
        List<WxConfig> list = wxConfigService.selectWxConfigList(wxConfig);
        return getDataTable(list);
    }

    /**
     * 导出微信登录，支付信息列表
     */
    @Operation(summary = "导出微信登录，支付信息列表")
    @PreAuthorize("@ss.hasPermi('wx:config:export')")
    @Log(title = "微信登录，支付信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxConfig wxConfig)
    {
        List<WxConfig> list = wxConfigService.selectWxConfigList(wxConfig);
        ExcelUtil<WxConfig> util = new ExcelUtil<>(WxConfig.class);
        util.exportExcel(response, list, "微信配置数据");
    }

    /**
     * 获取微信登录，支付信息详细信息
     */
    @Operation(summary = "获取微信登录，支付信息详细信息")
    @PreAuthorize("@ss.hasPermi('wx:config:query')")
    @GetMapping(value = "/{wxId}")
    public AjaxResult getInfo(@PathVariable("wxId") Long wxId)
    {
        return success(wxConfigService.selectWxConfigByWxId(wxId));
    }

    /**
     * 新增微信登录，支付信息
     */
    @Operation(summary = "新增微信登录，支付信息")
    @PreAuthorize("@ss.hasPermi('wx:config:add')")
    @Log(title = "微信登录，支付信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxConfig wxConfig)
    {
        return toAjax(wxConfigService.insertWxConfig(wxConfig));
    }

    /**
     * 修改微信登录，支付信息
     */
    @Operation(summary = "修改微信登录，支付信息")
    @PreAuthorize("@ss.hasPermi('wx:config:edit')")
    @Log(title = "微信登录，支付信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxConfig wxConfig)
    {
        return toAjax(wxConfigService.updateWxConfig(wxConfig));
    }

    /**
     * 删除微信登录，支付信息
     * 逻辑删除，删除后不显示，但还存在数据库中
     * @param wxIds
     * @return
     */
    @Operation(summary = "批量删除微信登录，支付信息--逻辑删除")
    @PreAuthorize("@ss.hasPermi('wx:config:remove')")
    @Log(title = "微信登录，支付信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wxIds}")
    public AjaxResult remove(@PathVariable Long[] wxIds)
    {
        return toAjax(wxConfigService.fakeDelWxConfigByWxIds(wxIds));
    }

    /**
     * 删除微信登录，支付信息
     * 真删除，删除后数据库不存在
     * @param wxIds
     * @return
     */
    @Operation(summary = "批量删除微信登录，支付信息--真删除")
    @PreAuthorize("@ss.hasPermi('wx:config:realRemove')")
    @Log(title = "微信登录，支付信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/realDel/{wxIds}")
    public AjaxResult realRemove(@PathVariable Long[] wxIds)
    {
        return toAjax(wxConfigService.realDelWxConfigByWxIds(wxIds));
    }
}
